#!/usr/bin/ruby -d

require 'sqlite3'
require 'singleton'


class TaskStorage
  include Singleton

  @@dbname = 'tsqlite3.db'
  @@task_table = 't3'

  def initialize
    @db = SQLite3::Database.new( @@dbname )
  end

  def get_current_tasks(date, time)
    rows = @db.execute( "SELECT id, submitter, subject, date, time FROM #{@@task_table} WHERE date = '#{date}' AND time = '#{time}' AND pending > 0;" )
  end

  def store(subm, subj, date, time)
    @db.execute( "INSERT INTO #{@@task_table} VALUES ( ?, ?, ?, ?, ?, ?)", nil, subm, subj, date, time, 1 )
  end

  def reset_current_tasks(date, time)
    @db.execute("UPDATE #{@@task_table} SET pending = 0 WHERE date = ? AND time = ?", date, time)
  end
end
